closeWindow = function () {
    parent.layer.close(parent.layer.getFrameIndex(window.name));
};

submitSure = function () {//普通转诊
    var doctor = $("#newDoctor").html();
    var customerId = $("#id").val();
    var remarks = $("#remarks").val();
    var time = $("#time").val();
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/updateDoctor",
        type: "post",
        data:{
            doctor:doctor,
            customerId:customerId,
            remarks:remarks,
            time:time,
            optType:'0'  //普通请求转正
        },
        success: function (data) {
            if(data == -2){//转正医生有冲突,执行弹出框是否继续转正
                if (confirm("预约时间不在当前医生工作时间内,是否继续转诊")) {
                    submitSpecialSure()
                }
            }else{
                Feng.success('操作成功!');
                window.parent.DoctorLooked.search();
                $('#cancel').click();
            }
        },
        error: function (data) {
            alert('没有权限，请联系管理员!');
        }
    });
};

submitSpecialSure = function () {//强制转诊
    var doctor = $("#newDoctor").html();
    var customerId = $("#id").val();
    var remarks = $("#remarks").val();
    var time = $("#time").val();
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/updateDoctor",
        type: "post",
        data:{
            doctor:doctor,
            customerId:customerId,
            remarks:remarks,
            time:time,
            optType:'1'  //强制请求转正
        },
        success: function (data) {
             Feng.success('操作成功!');
            window.parent.DoctorLooked.search();
            $('#cancel').click();
        },
        error: function (data) {
            alert('没有权限，请联系管理员!');
        }
    });
};

var myDate = new Date();
var month;
var day;
if ((myDate.getMonth() + 1) < 10) {
    month = "0" + (myDate.getMonth() + 1);
} else {
    month = "" + (myDate.getMonth() + 1);
}
if (myDate.getDate() < 10) {
    day = "0" + myDate.getDate();
} else {
    day = "" + myDate.getDate();
}

$(function () {
    document.getElementById("time").value = myDate.getFullYear() + "-" + month + "-" + day;
    $.ajax({
        url: Feng.ctxPath + "/consultant/getDoctor",
        type: "get",
        success: function (data) {
            var txt = '';
            for (var i = 0; i < data.length; i++) {
                txt += '<span>' + data[i].doctor + '</span>';
            }
            document.getElementById('doctorBox').innerHTML = txt;
        },
        error: function (data) {
            alert('没有权限，请联系管理员!');
        }
    });

    $("#doctorBox").on('click','span',function () {
        $("#newDoctor").html($(this).text());
        $(this).addClass('selectionSpan').siblings().removeClass('selectionSpan')
    });
    var date = new Date();
    var currentYear = date.getFullYear();       // 当前年份
    var currentMonth = date.getMonth() + 1;    // 当前月份
    var currentDay = date.getDate();         // 今日日期 几号
    if (currentMonth < 10) currentMonth = "0" + currentMonth;
    if (currentDay < 10) currentDay = "0" + currentDay;
    $("#time").val(currentYear+"-"+currentMonth+"-"+currentDay)
});